package com.edais.actions;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.edais.service.SystemIdWorkerService;
import com.edais.util.CommonUtil;
import com.edais.util.Consts;
import com.edais.util.JsonUtil;
import com.edais.util.Message;

@Controller
@RequestMapping("/sysIdWorker")

public class SysIdWorkerAction  implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final Log logger = LogFactory.getLog(SysIdWorkerAction.class);
	
	@Autowired
	private SystemIdWorkerService systemIdWorkerService;

	/** 得到生成的编号
	 * @param request
	 * @return response
	 * @throws Exception */
	@RequestMapping(value = "/getAutoLoanId",method = RequestMethod.GET)
	public void getAutoLoanId(HttpServletRequest request, HttpServletResponse response){
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		// 类别：
		String idType = paramsMap.get("idType");
		idType="02";
		//校验用户id
		if (StringUtils.isBlank(idType)) {
			logger.debug("/sysIdWorker/getAutoLoanId 传入参数为空");
			return;
		}
		try{
			// 发送短信
			String loanId = systemIdWorkerService.getAutoLoanId(idType);	
			jsonMap.put("autoLoanId", loanId);	
			jsonMap.put("rescode", Consts.SUCCESS_CODE);
			jsonMap.put("resmsg", "");
			jsonMap.put("resmsg_cn", "");
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("sysIdWorker/getAutoLoanId 异常:" + e.getMessage());
			jsonMap.put("rescode", Consts.ERROR_CODE);
			jsonMap.put("resmsg", Consts.ErrorMsg.MSG00001);
			jsonMap.put("resmsg_cn", Message.CnDescriptionExpression.BUSINESSE_ERROR);
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}		
	}
	
}
